<template>
    <div>
        <el-breadcrumb separator-class="el-icon-arrow-right">
            <el-breadcrumb-item :to="{ path: '/index' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>系统中心</el-breadcrumb-item>
            <el-breadcrumb-item>销售管理</el-breadcrumb-item>
        </el-breadcrumb>
        <el-card class="box-card">

            <el-button  type="primary" @click="dialogVisible = true">添加记录</el-button>

            <el-table
                    :data="recordList"
                    style="width: 100%">
                <el-table-column
                        type="index"
                        width="80">
                </el-table-column>
                <el-table-column
                        prop="sellerId"
                        label="销售Id"
                        width="100">
                </el-table-column>
                <el-table-column
                        prop="teacherId"
                        label="教师Id"
                        width="100">
                </el-table-column>
                <el-table-column
                        prop="studentId"
                        label="学生Id"
                        width="100">
                </el-table-column>
                <el-table-column
                        prop="classId"
                        label="课程Id"
                        width="100">
                </el-table-column>
                <el-table-column
                        prop="changeFee"
                        label="提成变化"
                        width="160">
                </el-table-column>
                <el-table-column
                        prop="sellerFee"
                        label="最总提成"
                        width="160">
                </el-table-column>
                <el-table-column
                        prop="changeReason"
                        label="提交记录"
                        width="160">
                </el-table-column>
            </el-table>
            <div class="block">
                <el-pagination
                        @size-change="handleSizeChange"
                        @current-change="handleCurrentChange"
                        :current-page="page.pageCurrent"
                        :page-sizes="[5, 10, 15, 20]"
                        :page-size="page.pageSize"
                        layout="total, sizes, prev, pager, next, jumper"
                        :total="total">
                </el-pagination>
            </div>
        </el-card>
        <el-dialog
                title="添加记录"
                :visible.sync="dialogVisible"
                width="30%">
            <el-form ref="form" :model="recordForm" label-width="80px" >
                <el-form-item label="销售Id">
                    <el-input v-model="recordForm.sellerId"></el-input>
                </el-form-item>
                <el-form-item label="教师Id">
                    <el-input v-model="recordForm.teacherId"></el-input>
                </el-form-item>
                <el-form-item label="学生Id">
                    <el-input v-model="recordForm.studentId"></el-input>
                </el-form-item>
                <el-form-item label="科目">
                    <el-select v-model="recordForm.classId" placeholder="请选择科目">
                        <el-option
                                v-for="item in subjectList"
                                :label="item.subjectName"
                                :value="item.id">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="提成金额">
                    <el-input v-model="recordForm.changeFee"></el-input>
                </el-form-item>
                <el-form-item label="提交记录">
                    <el-input v-model="recordForm.changeReason"></el-input>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="clearRecord">取 消</el-button>
                 <el-button type="primary" @click="addRecord">确 定</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
import moment from "moment";

    export default {
        name: "recordList",
        data(){
            return{
                recordList:[],
                recordForm:{},
                subjectList:[],
                dialogVisible:false,
                page:{
                    pageCurrent:0,
                    pageSize:5
                },
                total:0,
            }
        },
        methods:{
            //实现分页
            //每页记录数
            handleSizeChange:function(val){
                this.page.pageSize = val
                this.recordSel()
            },
            //当前页
            handleCurrentChange:function(val){
                this.page.pageCurrent = val
                this.recordSel()
            },

            //列表实现
            recordSel:function () {
                this.$http.post('/admin/getTbSellerFeeRecord?pageCurrent='+this.page.pageCurrent+
                    '&pageSize='+this.page.pageSize).then((res)=>{
                    this.recordList = res.data.result.pages.records
                    this.total =  res.data.result.pages.total;
                })
            },

            //逻辑删除
            delById:function (id) {
                this.$http.post('/admin/delTbSellerFeeRecord?id='+id).then((res)=>{
                    if (res.data.success) {
                        this.$message({
                            message: res.data.message,
                            type: 'success'
                        });
                    }
                    this.recordSel();
                })
            },

            //科目追加
            subjectSel:function () {
                //debugger;
                this.$http.get('/admin/getSubjectAll').then((res)=>{
                    this.subjectList = res.data.result.subjects
                })
            },

            //添加记录
            addRecord:function () {
                this.$http.post('admin/addTbSellerFeeRecord?sellerId='+this.recordForm.sellerId+
                    '&teacherId='+this.recordForm.teacherId+
                    '&studentId='+this.recordForm.studentId+
                    '&classId='+this.recordForm.classId+
                    '&changeFee='+this.recordForm.changeFee+
                    '&changeReason='+this.recordForm.changeReason).then((res)=>{
                    if (res.data.success) {
                        this.$message({
                            message: res.data.message,
                            type: 'success'
                        });
                    }else {
                        this.$message({
                            message: res.data.message,
                            type: 'error'
                        });
                    }
                    this.clearRecord();
                })
            },



            //清空表单
            clearRecord:function(){
                this.dialogVisible=false
                this.recordForm.sellerId=""
                this.recordForm.teacherId=""
                this.recordForm.studentId=""
                this.recordForm.classId=""
                this.recordForm.changeFee=""
                this.recordForm.changeReason=""
                this.recordSel()
            }

        },
        filters:{
            adminStatusFit:function (val) {
                if (val == '0'){
                    return "正常"

                }
                if (val == '1'){
                    return "锁定"
                }
            },
            createTimeFit:function (val) {
                return moment(val).format("YYYY-MM-DD hh:mm:ss")
            },
        },
        mounted() {
            this.recordSel();
            this.subjectSel();
        }

    }
</script>

<style scoped>


</style>

